<template>
  <div class="m-login">
    <div class="content">
      <h1><br>婚庆管理系统</h1>
      <div class="login-form">
        <el-input type="email" placeholder="请输入用户名" icon="user" v-model.trim="userName">
        </el-input>
        <div class="el-input">
          <i class="el-input__icon el-icon-password"></i>
          <el-input
          @keyup.enter="login"
          type="password"
          placeholder="请输入密码"
          autocomplete="off"
          v-model.trim="password"
          @keyup.enter.native="login()">
          </el-input>
        </div>
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'login',
    data() {
      return {
        userName: '',
        password: ''
      }
    },
    methods: {
      login() {
        let user = {
          "password": this.password,
          "phone": this.userName
        }
        this.api.post('/api/login',user).then(res=>{
          if(res.code == 200){
            localStorage.token=JSON.stringify(res.data);
            this.$message({
              type:'success',
              message:'登录成功！正在为您跳转页面'
            })
            setTimeout(()=>{
              this.$router.push('./mainstay/home')
            },2000)

          }
        })
      }
    }
  }
</script>
<style scoped lang="less">
  .m-login {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background: url("../assets/login-bg.png") no-repeat center;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;

    .content {
      width: 350px;
      margin-top: -250px;
      text-align: center;
      color: white;

      h1 {
        font-weight: normal;
        margin-bottom: 20px;
      }

      .el-alert {
        margin-bottom: 28px;
      }

      .login-form {
        padding: 40px 30px;
        background: rgba(255, 255, 255, 0.30);
        box-shadow: 0px 5px 4px 1px rgba(113, 116, 121, 0.37);
        border-radius: 10px;

        .el-input__icon {
          left: 0;
          right: auto;
        }

        .el-input__icon+.el-input__inner {
          padding-right: 0;
        }

        .el-icon-user:after {
          width: 18px;
          height: 20px;
          background: url("../assets/icon/user.png");
          background-size: 100% 100%;
          margin-top: 7px;
        }

        .el-icon-password:after {
          width: 15px;
          height: 20px;
          background: url("../assets/icon/password.png");
          background-size: 100% 100%;
          margin-top: -20px;
        }

        .el-input:nth-child(1) {
          margin-bottom: 20px;
        }

        .el-button {
          width: 100%;
          margin-top: 30px;
        }
      }
    }
  }
</style>
